package top.hzy520.config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 17:31 2018/7/7
 */
@Configuration
@MapperScan(basePackages = {"top.hzy520.user.dao"},sqlSessionFactoryRef = "userSqlSessionFactory")
public class UserSqlSessionConfig {
     @Autowired
     @Qualifier("userDataSource")
     private DataSource stockDatasource;

      @Bean(name = "userSqlSessionFactory")
     public SqlSessionFactory userSqlSessionFactory() throws Exception {
          SqlSessionFactoryBean factoryBean=new SqlSessionFactoryBean();
          factoryBean.setDataSource(stockDatasource);
          return factoryBean.getObject();
      }
      @Bean(name = "userSqlSessionTemplate")
      public SqlSessionTemplate userSqlSessionTemplate() throws Exception {
        SqlSessionTemplate sqlSessionTemplate=new SqlSessionTemplate(userSqlSessionFactory());
        return sqlSessionTemplate;
      }
}
